//
//  SAMKeychain+ADUtil.m
//  ADKit
//
//  Created by duzexu on 2017/11/30.
//  Copyright © 2017年 duzexu. All rights reserved.
//

#import "SAMKeychain+ADUtil.h"
#import "ADKitHeaders.h"

static NSString *const AD_DEVICEID_ACCOUNT = @"AD_DEVICEID_ACCOUNT";

@implementation SAMKeychain (ADUtil)

+ (NSString *)ad_passwordForAccount:(NSString *)account {
    return [self passwordForService:UIApplication.sharedApplication.appBundleID account:account];
}

+ (NSData *)ad_passwordDataForAccount:(NSString *)account {
    return [self passwordDataForService:UIApplication.sharedApplication.appBundleID account:account];
}

+ (BOOL)ad_setPasswordData:(NSData *)password forAccount:(NSString *)account {
    return [self setPasswordData:password forService:UIApplication.sharedApplication.appBundleID account:account];
}

+ (BOOL)ad_setPassword:(NSString *)password forAccount:(NSString *)account {
    return [self setPassword:password forService:UIApplication.sharedApplication.appBundleID account:account];
}

+ (BOOL)ad_deletePasswordForAccount:(NSString *)account {
    return [self deletePasswordForService:UIApplication.sharedApplication.appBundleID account:account];
}

+ (NSString *)ad_deviceID {
    NSString *device = [SAMKeychain passwordForService:[UIApplication sharedApplication].appBundleID account:AD_DEVICEID_ACCOUNT];
    if (device == nil) {
        device = [UIDevice currentDevice].identifierForVendor.UUIDString;
        [SAMKeychain setPassword:device forService:[UIApplication sharedApplication].appBundleID account:AD_DEVICEID_ACCOUNT];
    }
    return device;
}

@end
